<?php

use yak\layui\widgets\grid\LayuiGridView;
use yii\helpers\Url;

/* @var $this yii\web\View */
/* @var $searchModel yak\layui\search\AdminSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '管理员';
$this->params['breadcrumbs'][] = ['label' => $this->title, 'icon' => 'layui-icon-user'];
$this->params['link'] = Url::toRoute('index');
?>
<div class="admin-index">

    <script type="text/html" id="toolBar">
        <a class="layui-btn layui-btn-normal layui-btn-sm" lay-event="create">
            <i class="layui-icon layui-icon-file-b"> 新建管理员</i>
        </a>
    </script>

    <script type="text/html" id="tool">
        <a class="layui-btn layui-btn-warm layui-btn-xs"
           href="<?= Url::toRoute('assign') ?>?id={{d.id}}&name={{d.name}}">权限分配</a>
        
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>

    <div class="layui-card">
        <div class="layui-card-header yak-search-card-header">
            <?php echo $this->render('_search', ['model' => $searchModel]); ?>
        </div>
        <div class="layui-card-body">
            <table id="admin-table" lay-filter="admin-table-filter"></table>
        </div>
    </div>

    <?= LayuiGridView::widget([
        'searchModel' => $searchModel,
        'dataProvider' => $dataProvider,
        'tableId' => 'admin-table',
        'tableFilter' => 'admin-table-filter',
        'searchFilter' => 'admin-search',
        // 'sort' => 'server',
        'tableOptions' => [
            'url' => Url::toRoute(['index']),
            'toolbar' => '#toolBar',
            'page' => [
                'hash' => 'fenye'
            ],
            'defaultToolbar' => [
                'filter',
                'print',
                [
                    'title' => '导出Excel',
                    'layEvent' => 'OUTPUT_EXCEL',
                    'icon' => 'layui-icon-export',
                ]
            ]
        ],
        'editorOptions' => [
            'url' => Url::toRoute(['update']),
            'method' => 'get',
        ],
        'eventOptions' => [
            'detail' => [
                'url' => Url::toRoute(['view'])
            ],
            'edit' => [
                'url' => Url::toRoute(['update']),
                'openRefresh' => true
            ],
            'del' => [
                'url' => Url::toRoute(['delete']),
                'message' => '确定删除该项目？'
            ],
            'create' => [
                'url' => Url::toRoute(['create']),
                'openRefresh' => true
            ],
            'OUTPUT_EXCEL' => [
                'url' => Url::toRoute(['output']),
                'filename' => '菜单列表'
            ],
            'deleteBatch' => [
                'url' => Url::toRoute(['batch-delete']),
                'message' => '确定删除？'
            ]
        ]
    ]) ?>

</div>
